using Behaving;

namespace Behaving.Tests
{
    public class ExecutionCounter : Behaviour
    {
        public ExecutionCounter(RunningState runningState = RunningState.Success)
        {
            RunningState = runningState;
        }

        public RunningState RunningState { get; set; }
        public int StartCalls { get; set; }
        public int ExecuteCalls { get; set; }
        public int StopCalls { get; set; }

        public override void Start(BehaviourTree behaviourTree)
        {
            base.Start(behaviourTree);
            StartCalls++;
        }

        public override string ToString()
        {
            return string.Format(
                "ExCntr: Sta={0}, Ex={1}, Sto={2}, RS={3}", 
                StartCalls,
                ExecuteCalls,
                StopCalls,
                RunningState);
        }

        public override RunningState Execute(BehaviourTree behaviourTree)
        {
            ExecuteCalls++;
            return RunningState;
        }

        public override void Stop(BehaviourTree behaviourTree)
        {
            StopCalls++;
            base.Stop(behaviourTree);
        }

        public void Reset()
        {
            StartCalls = 0;
            ExecuteCalls = 0;
            StopCalls = 0;
        }
    }
}